%% Results
% Generates all results presented in the paper


%% No debt case

clear;
tic
[bParams, oParams, setts] = model_settings(1);
[Mom_nd, dataSim_nd, f_nd, entrant_nd, lambda_e_nd, equity_mat_nd, debt_mat_nd, lambda_mat_nd, coupon_mat_nd, optimal_firm_nd, optimal_coupon_nd] = moments(bParams,oParams,setts);
toc
Mom_nd

save([setts.dir,'nodebt_results.mat']);

%% Static debt case

clear;
tic
[bParams, oParams, setts] = model_settings(2);
[Mom_ds, dataSim_ds, f_ds, entrant_ds, lambda_e_ds, equity_mat_ds, debt_mat_ds, lambda_mat_ds, coupon_mat_ds, optimal_firm_ds, optimal_coupon_ds] = moments(bParams,oParams,setts);
toc
Mom_ds

save([setts.dir,'static_results.mat']);


%% Breakeven elasticity

clear;
[bParams, oParams, setts] = model_settings(1);

[Mom_nd, ~, f_nd] = moments(bParams,oParams,setts);
H_baseline = bParams.H;

% Solve breakeven no debt model
[bParams, oParams, setts] = model_settings(2);
upMat = updatematrix(bParams,oParams,setts);
H_ds = entrant_value(bParams,oParams,setts,upMat,f_nd)/(1-oParams.pi);
bParams.H = H_ds;
[Mom_ds_be, ~, f_ds_be] = moments(bParams,oParams,setts);

% Elasticity
disp(sprintf('Breakeven elasticity check f is the same: %0.5g',(f_nd-f_ds_be)))
elasticity_breakeven_nd_fixed = log((Mom_ds_be.flow_new_entrants)/(Mom_nd.flow_new_entrants))/log(H_ds/H_baseline)
disp(sprintf('The breakeven elasticity fixing the no debt case is %0.5g',elasticity_breakeven_nd_fixed))

%% Comparative statics

comparative_statics

%% Comparative statics table (Table 2 (except data row) and 3)

comparative_statics_table

%% Figures (All figures except for Figure 1, 2, and 4)

figures
